<?php
declare (strict_types=1);

namespace app\pc\controller\base;

use app\admin\model\advertiser\AdvertiserSecondary;
use app\admin\model\advertiser\AdvertiserSecondaryLog;
use app\BaseController;
use app\pc\service\base\IndexService;
use redis\RedisTools;
use think\response\Json;

/**
 * 首页大厅
 */
class Index extends BaseController
{

    /**
     * 大厅首页
     */
    public function index(IndexService $indexService):Json
    {

        return $indexService->index([]);
    }

    /**
     * 查看今日次数
     * @return void
     */
    public function today()
    {
        $arr = [
            'V1_Way_7_0',
            'V1_Way_7_1',
            'V1_Way_7_2',
            'V1_Way_7_3',
            'V1_Way_7_4',
            'V1_Way_7_5',
            'V1_Way_7_6',
            'V1_Way_7_7',
            'V1_Way_7_8',
            'V2_Way_4_0',
            'V2_Way_3_0',
        ];
        $redis = RedisTools::getInstance(config('cache.stores.redis'), 0)->getRedis();
        foreach ($arr as $item){
            $key = $item.'_'.date('Y-m-d').'_num';
            $num = $redis->get($key);
            $num = !empty($num) ? $num : 0;
            echo '路径：'.$item.'，今日识别数：'.$num.'<br>';
        }

        echo '<hr >';
        //获取二关任务数据
        echo '二关任务数据'.'<br>';
        $lists = AdvertiserSecondary::order('id desc')->select()->toArray();
        $time = strtotime(date('Y-m-d',time()))+86400;
        if(!empty($lists)){
            foreach ($lists as $values){
                for ($i = 0; $i < 10;$i++){
                    $num = AdvertiserSecondaryLog::where('third_id','=',$values['id'])
                        ->where('create_time','>',$time-(86400*($i+1)))
                        ->where('create_time','<',$time-(86400*$i))
                        ->count();
                    echo '任务ID：'.$values['id'].'，名称：'.$values['name'].'，日期：'.date('Y-m-d',$time-(86400*($i+1))).'，数量：'.$num.'<br>';
//                    $datas[] = [
//                        'date'=>date('Y-m-d',($time - 86400)),
//                        'num'=>AdvertiserSecondaryLog::where('third_id','=',$values['id'])->where('create_time','>',$time)->count();
//                    ];
                }
//                $num = AdvertiserSecondaryLog::where('third_id','=',$values['id'])->where('create_time','>',$time)->count();
            }
        }
        if(!empty($listss)){
            foreach ($listss as $values){
                $num = AdvertiserSecondaryLog::where('third_id','=',$values['id'])->where('create_time','>',$time)->count();
                echo '任务ID：'.$values['id'].'，数量：'.$num.'<br>';
            }
        }

//        $list = ScanBagStatistics::order('date desc')->select()->toArray();
//        //往日识别数据
//        echo '<hr >';
//        if(!empty($list)){
//            foreach ($list as $value){
//                echo '路径：'.$value['key'].'，日期：'.$value['date'].'，数量：'.$value['num'].'<br>';
//            }
//        }
    }

}
